﻿using System;
using System.Collections.Generic;
using System.Text;
using KBEngine.Setting.TypeDef;

namespace KBEngine.Export
{
    public abstract class CSharpExport
    {
        protected virtual string GetTypeName(IType iType, bool switchBaseName = true)
        {
            var type = iType.GetType();
            if (type == typeof(BaseType))
                return switchBaseName ? GetCSharpBaseName(iType.TypeName) : iType.TypeName;
            else if (type == typeof(AliasType))
                return GetTypeName(((AliasType)iType).RealType, switchBaseName);
            else if (type == typeof(ArrayType))
                return $"List<{GetTypeName(((ArrayType)iType).ElementType, switchBaseName)}>";
            else if (type == typeof(UserType))
                return iType.TypeName;

            throw new InvalidOperationException("GetCSharpTypeString() " + type.Name);
        }
        private string GetCSharpBaseName(string baseName)
        {
            switch (baseName)
            {
                case "UINT8":
                    return "Byte";
                case "UINT16":
                    return "UInt16";
                case "UINT32":
                    return "UInt32";
                case "UINT64":
                    return "UInt64";

                case "INT8":
                    return "SByte";
                case "INT16":
                    return "Int16";
                case "INT32":
                    return "Int32";
                case "INT64":
                    return "Int64";

                case "FLOAT":
                    return "float";
                case "DOUBLE":
                    return "double";

                case "VECTOR2":
                    return "Vector2";
                case "VECTOR3":
                    return "Vector3";
                case "VECTOR4":
                    return "Vector4";

                case "STRING":
                    return "string";
                case "UNICODE":
                    return "string";
                case "PYTHON":
                    return "byte[]";
                case "PY_DICT":
                    return "byte[]";
                case "PY_TUPLE":
                    return "byte[]";
                case "PY_LIST":
                    return "byte[]";
                case "MAILBOX":
                    return "byte[]";
                case "BLOB":
                    return "byte[]";
                default:
                    throw new InvalidOperationException("GetCSharpTypeString() " + baseName);
            }
        }
    }
}
